package com.yanqu.road.server.cmd.group;

import com.yanqu.road.entity.enums.eServerGroup2Type;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.player.UserDecoration;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.cross.group.CrossGroupProto;
import com.yanqu.road.pb.decoration.DecorationProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.rank.CrossRankMgr;
import com.yanqu.road.server.manger.MammonConfigMgr;
import com.yanqu.road.server.manger.ServerGroup2Mgr;
import com.yanqu.road.server.manger.ServerGroupMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_CROSS_GROUP_MAMMON_CHANGE, desc = "跨服分组财神数据变化")
public class CrossGroupMammonChangeCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossGroupProto.CrossGroupMammonChangeReqMsg reqMsg = CrossGroupProto.CrossGroupMammonChangeReqMsg.parseFrom(packet.getBytes());

        int crossGroupId = ServerGroupMgr.getGroupIdByServerId(serverId);
        int crossAreaGroupId = ServerGroup2Mgr.getServerGroup2Id(eServerGroup2Type.CrossAreaMammon, serverId);

        long userId = reqMsg.getUserId();
        UserBaseInfo userBaseInfo = PlayerBasePb.parseToUserBaseInfo(reqMsg.getUserBaseInfo());
        for(DecorationProto.DecorationTempMsg temMsg : reqMsg.getDataListList()) {
            UserDecoration userDecoration = new UserDecoration();
            userDecoration.setUserId(userId);
            userDecoration.setDecorationId(temMsg.getDecorationId());
            userDecoration.setEndTime(temMsg.getEndTime());

            if (MammonConfigMgr.isCrossAreaMammonDecorationId(userDecoration.getDecorationId())) {
                CrossRankMgr.changeAreaUserMammon(crossAreaGroupId, userId, userBaseInfo, userDecoration);
            } else {
                CrossRankMgr.changeUserMammon(crossGroupId, userId, userBaseInfo, userDecoration);
            }

        }
    }

    @Override
    public void sendData() {

    }
}
